package cn.ichiva.tushare.analysis.data;

import cn.ichiva.tushare.analysis.Config;
import cn.ichiva.tushare.analysis.data.国内宏观.利率数据.Shibor;
import cn.ichiva.tushare.sdk.common.DateUtils;
import cn.ichiva.tushare.sdk.tushare.TuClient;
import cn.ichiva.tushare.sdk.tushare.TuDataCacheAble;
import cn.ichiva.tushare.sdk.tushare.entity.TuRequest;
import cn.ichiva.tushare.sdk.tushare.entity.TuTable;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 上证（默认）交易日历
 *
 * 获取各大交易所交易日历数据,默认提取的是上交所
 */
public class TradeCal extends TuDataCacheAble {

    public TradeCal(TuClient client) {
        super(client);

        TuRequest request = new TuRequest();
        request.setApi("trade_cal");
        request.setDescribe("获取各大交易所交易日历数据,默认提取的是上交所");

        HashMap<String,String> paramsMap = new HashMap<>();
        paramsMap.put("start_date","20140101");
        paramsMap.put("end_date", DateUtils.lastTUDateString());
        request.setParams(paramsMap);

        LinkedHashMap<String,String> fieldMap = new LinkedHashMap<>();
        fieldMap.put("exchange","交易所 SSE上交所 SZSE深交所 ");
        fieldMap.put("cal_date","日历日期 ");
        fieldMap.put("is_open","是否交易 0休市 1交易 ");
        fieldMap.put("pretrade_date","上一个交易日 ");

        request.setFieldMap(fieldMap);
        setRequest(request);
    }

    private static final List<String> tradingDay;
    static {
        TradeCal tradeCal = new TradeCal(new TuClient(Config.url, Config.token));
        TuTable tuTable = tradeCal.get().get();
        List<String> list = Arrays.stream(tuTable.getItems())
                .filter(e -> "1".equals(e[2]))
                .map(e -> e[1]).collect(Collectors.toList());
        tradingDay = Collections.unmodifiableList(list);
    }
    public static List<String> getTradingDay(){
        return tradingDay;
    }

    public static void main(String[] args) {
        tradingDay.forEach(System.out::println);
    }
}
